<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <title>在线执行代码看结果</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <link rel="stylesheet" href="lib/bootstrap.min.css"/>
    <link rel="stylesheet" href="lib/codemirror.css"/>
</head>
<body>
<div style=" margin: 20px;">
    <label>选择模块</label>
    <select name="module-code" id="module">
        <option value="waimai" selected="selected">dbc</option>
    </select>
        <textarea id="text-code" class="input-xlarge" style="width: 100%;height: 200px;">
            lalal
        </textarea>
        <div style="text-align: center">
            <button id="submit-code" class="btn btn-large">code here</button>
        </div>
        <div id="code-result" class="well" style="text-align: left; margin-top: 10px;">
            在上面写电影的php代码 直接运行看结果
        </div>
</div>
<script src="lib/jquery-1.10.2.js"></script>
<script src="lib/codemirror.js"></script>
<script src="mode/htmlmixed/htmlmixed.js"></script>
<script src="mode/xml/xml.js"></script>
<script src="mode/javascript/javascript.js"></script>
<script src="mode/css/css.js"></script>
<script src="mode/clike/clike.js"></script>
<script src="mode/php/php.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        document.getElementById("text-code").value ="<?"+"php \n\nvar_dump(123);";
        var editor = CodeMirror.fromTextArea(document.getElementById("text-code"),{
            lineNumbers: true,
            matchBrackets: true,
            mode: "application/x-httpd-php",
            indentUnit: 4,
            indentWithTabs: true,
            enterMode: "keep",
            tabMode: "shift"
        });

        $("#submit-code").click(function(){
            var data = {
                code : editor.doc.getValue().replace("<?php","").replace("?>", ""),
                module: $("#module").val()
            };
            $.post("/dbc/code", data, function(r){
                if(r) {
                    $('#code-result').html(r);
                }
                else {
                    $('#code-result').html("请检查: 1. 是不是没写输出语句？2. php运行失败，请查看/home/lv/log/php-error.log");
                }
            });
        });
    });
</script>
</body>
</html>
